package yz.cp.back.s.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import yz.cp.back.s.entity.SysDepartment;
import yz.cp.back.s.mapper.SysDepartmentMapper;
import yz.cp.back.s.service.ISysDepartmentService;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-04-03
 */
@Service
public class SysDepartmentServiceImpl extends ServiceImpl<SysDepartmentMapper, SysDepartment> implements ISysDepartmentService {
    @Override
    public List<SysDepartment> findByParentIdOrderBySortOrder(String parentId) {
        Wrapper wrapper=new QueryWrapper<SysDepartment>().lambda()
                .eq(SysDepartment::getParentId,parentId)
                .orderByAsc(SysDepartment::getSortOrder);
        return list(wrapper);
    }

    @Override
    public List<SysDepartment> findByParentIdAndIdInOrderBySortOrder(String parentId, List<String> departmentIds) {
        Wrapper wrapper=new QueryWrapper<SysDepartment>().lambda()
                .eq(SysDepartment::getParentId,parentId)
                .in(SysDepartment::getId,departmentIds)
                .orderByAsc(SysDepartment::getSortOrder);
        return list(wrapper);
    }

    @Override
    public List<SysDepartment> findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status) {
        Wrapper wrapper=new QueryWrapper<SysDepartment>().lambda()
                .eq(SysDepartment::getParentId,parentId)
                .eq(SysDepartment::getStatus,status)
                .orderByAsc(SysDepartment::getSortOrder);
        return list(wrapper);
    }

    @Override
    public List<SysDepartment> findByTitleLikeOrderBySortOrder(String title) {
        Wrapper wrapper=new QueryWrapper<SysDepartment>().lambda()
                .like(SysDepartment::getTitle,title)
                .orderByAsc(SysDepartment::getSortOrder);
        return list(wrapper);
    }

    @Override
    public List<SysDepartment> findByTitleLikeAndIdInOrderBySortOrder(String title, List<String> departmentIds) {
        Wrapper wrapper=new QueryWrapper<SysDepartment>().lambda()
                .like(SysDepartment::getTitle,title)
                .in(SysDepartment::getId,departmentIds)
                .orderByAsc(SysDepartment::getSortOrder);
        return list(wrapper);
    }
}
